<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<head>
<title>Market place</title>
</head>
<f:view>
	<body>
		<ui:composition template="/templates/adminTemplate.xhtml">
			<ui:define name="content">

				<div id="center">
					<p:scrollPanel mode="native" style="font-size:0.9em">
						<h:form prependId="false" id="detailForm">
							<h:panelGrid columns="1" style="width:100%">
								<h:panelGrid columns="6" style="width:100%; font-size:0.9em;">
									<p:commandButton ajax="true" value="Reload"
										update=":detailForm:locationDataGrid" style="float:left"
										actionListener="#{reportController.loadOrdersByLocation}" />
									<h:panelGroup>
										<h:outputText value="Status:"></h:outputText>
										<h:outputText value="Confirmed" style="color:red; font-weight:bold;font-size:1.2em"/>
									</h:panelGroup>
									<h:panelGroup>
										<h:outputText value="Required Date:"></h:outputText>
										<p:calendar value="#{reportModel.orderQuery.requiredDate}" />
									</h:panelGroup>

									<h:commandLink value="Print delivery report">
										<p:fileDownload
											value="#{reportController.ordersByLocationPdf}"></p:fileDownload>
									</h:commandLink>
									<h:commandLink value="Print prepare report">
										<p:fileDownload
											value="#{reportController.ordersByLocationWithDetailPdf}"></p:fileDownload>
									</h:commandLink>
									<h:commandLink value="Print Location List">
										<p:fileDownload
											value="#{reportController.ordersByLocationLocationListPdf}"></p:fileDownload>
									</h:commandLink>
								</h:panelGrid>
								<p:dataGrid id="locationDataGrid" columns="1" style="width:100%"
									value="#{reportModel.ordersByLocation}" var="location">
									<p:panel header="#{location.number}-#{location.address}">
										<p:dataTable id="ordersByLocationTable" var="order"
											value="#{location.orders}" paginator="true" rows="20"
											rowsPerPageTemplate="5,7,10,15,20,30,40,50"
											paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">

											<p:column headerText="Number" sortBy="#{order.number}">
												<h:outputText value="#{order.number}" />
											</p:column>
											<p:column headerText="#{msgs.status}"
												sortBy="#{order.status.label}">
												<h:outputText value="#{order.status.label}" />
											</p:column>
											<p:column headerText="Customer">
												<h:outputText
													value="#{order.customer.lastName} #{order.customer.firstName}" />
											</p:column>
											<p:column headerText="Address">
												<h:outputText value="#{order.customer.address}" />
											</p:column>
											<p:column headerText="Telephone">
												<h:outputText value="#{order.customer.telephone}" />
											</p:column>
											<p:column headerText="Charge">
												<h:outputText value="#{order.confirmedTotalCharge}">
													<f:convertNumber type="currency" currencySymbol="$"
														maxFractionDigits="2" minFractionDigits="2"></f:convertNumber>
												</h:outputText>
											</p:column>
											<p:column headerText="Order detail">
												<p:dataTable value="#{order.orderDetails}" var="detail"
													paginator="false">
													<p:column>
														<h:outputText value="#{detail.product.number}"></h:outputText>
													</p:column>
													<p:column>
														<h:outputText value="#{detail.product.nameLabel}"></h:outputText>
													</p:column>
													<p:column headerText="Cfm. Qty.">
														<h:outputText
															value="#{detail.confirmedQuantity}/#{detail.product.stockUnitLabel}"></h:outputText>
													</p:column>
												</p:dataTable>
											</p:column>
										</p:dataTable>
									</p:panel>

								</p:dataGrid>

							</h:panelGrid>
						</h:form>
					</p:scrollPanel>
				</div>
			</ui:define>
		</ui:composition>
	</body>
</f:view>
</html>